package vn.buffalocoders.rikos.ui.home;

import vn.buffalocoders.rikos.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class BrowserFragment extends Fragment {

	HomeActivity mParent;
	private WebView mWebFragment;
	private String sURL;
	public static int mLoadedPage = 0;

	@Override
	public View onCreateView(LayoutInflater inflater, 
			ViewGroup container, Bundle savedInstanceState) {

		View view=inflater.inflate(
				R.layout.activity_home_fragment_webview, 
				container, 
				false);
		mWebFragment=(WebView)view.findViewById(R.id.my_browser);
		mWebFragment.setVerticalScrollBarEnabled(false);
		mWebFragment.setHorizontalScrollBarEnabled(false);
		mWebFragment.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

		mWebFragment.setWebViewClient(new WebViewClient()
		{
			public void onPageFinished(WebView view, String url)
			{
				if(BrowserFragment.mLoadedPage < mParent.getLength())
					BrowserFragment.mLoadedPage ++;
				if(BrowserFragment.mLoadedPage == mParent.getLength()) 
					mParent.hideTitleGroup();
			}
		});

		mWebFragment.loadUrl(sURL);
		return view;
	}


	// This is the method the pager adapter will use
	// to create a new fragment
	public static Fragment newInstance(HomeActivity parent, String url){
		BrowserFragment f=new BrowserFragment();
		f.mParent = parent;
		f.sURL=url;
		return f;
	}

}